package com.lill.common.component.api;

import com.lill.common.component.xss.XssHttpServletRequestWrapper;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

public class IBaseApi {
    // 平台机构id
    public final static String DEFAULT_COMPANY_ID = "6259d0b70a0d6b36a526fe4e87f9c9b4";

    @Autowired
    private HttpServletRequest request;

    public void addHeaderParams(Map<String, Object> params){
        if (request != null ) {
            XssHttpServletRequestWrapper xsrw = new XssHttpServletRequestWrapper(request);
            String apiCompanyId = xsrw.getHeader("apiCompanyId");
            String apiDepartId = xsrw.getHeader("apiDepartId");
            params.put("apiCompanyId",apiCompanyId);
            params.put("apiDepartId",apiDepartId);
            params.put("adminCompanyId",DEFAULT_COMPANY_ID);
//            Enumeration headerNames = request.getHeaderNames();
//            while (headerNames.hasMoreElements()) {
//                String key = (String) headerNames.nextElement();
//                if ("apiCompanyId".equals(key)) {
//                    String value = request.getHeader(key);
//                    params.put(key, value);
//                }
//                if ("apiDepartId".equals(key)) {
//                    String value = request.getHeader(key);
//                    params.put(key, value);
//                }
//            }
//            params.put("adminCompanyId",DEFAULT_COMPANY_ID);
        }
    }
}
